
/**
 * @Author: 陈瑞鹏
 * @Date:   2022-10-17 15:28:17
 * @Last Modified by:   陈瑞鹏
 * @Last Modified time: 2022-10-18 15:31:33
 */
import { FUNC_NAME } from "../enum/itemLogs.enum";
import Hero from "../models/hero/hero.model";
import User from "../models/user/user.model";
import reward from "./reward.controller";
export default class hero {

  /**
   * 武将初始化
   * @param roleId 角色ID
   */
  static async heroInit(roleId: number) {
    let HeroRes: any = await Hero.findOne({ roleId, id: 2002 });
    if (!HeroRes) {
      await reward.sendHero(roleId, 2002, `进入游戏赠送`, FUNC_NAME.INIT_GAME);
      await reward.sendHero(roleId, 3006, `进入游戏赠送`, FUNC_NAME.INIT_GAME);
      await User.updateOne({ roleId }, { warLineupArr: [2002], warTowerId: 3006 });
    }
  }


  /**
   * 获取武将总等级
   * @param roleId 角色ID
   * @returns
   */
  static async get_hero_total_lv(roleId: number) {
    let HeroRes: any = await Hero.find({ roleId });
    let totalLv = 0;
    for (const iterator of HeroRes) {
      totalLv += iterator.level
    }
    return totalLv;
  }
}